<!-- 公共文件 start -->
@extends('admin.public.base')
<!-- 公共文件 end -->

@section('content')
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-card-header">
                <button type="button" class="layui-btn layui-btn-danger"><i
                        class="layui-icon">&#xe735;</i>基础折扣率：{{ $data['discount_rate'] }}</button>
            </div>
            <div class="layui-card-body layui-table-body layui-table-main">
                <table class="layui-table layui-form">
                    <thead>
                        <tr>
                            <th>图片</th>
                            <th>商品名</th>
                            <th>商品分类</th>
                            <th>商品编号</th>
                            <th>标准价格</th>
                            <th>设定价格</th>
                            <th>最低起订量</th>
                            <th>销售策略(买)</th>
                            <th>销售策略(赠)</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach( $goodsList as $kk => $item)
                        <tr>
                            <td><img src="{{ $item['goods_img'] }}" height="40px" alt="品牌图"></td>
                            <td>{{ $item['goods_name'] }}</td>
                            <td>{{ $item['cate_name'] }}</td>
                            <td>{{ $item['goods_sn'] }}</td>
                            <td>{{ $item['goods_price'] }}</td>
                            <td>
                                @if ($item['fixed_price'] == 1 || $item['promotion'] == 1)
                                <input type="number" readonly name="goods[{{$kk}}][sale_price]"
                                    value="{{$item['goods_price']}}" class="layui-input layui-disabled">
                                @else
                                <input type="number" name="goods[{{$kk}}][sale_price]" value="{{$item['sale_price']}}"
                                    class="layui-input">
                                @endif
                            </td>
                            <td>
                                <input type="number" name="goods[{{$kk}}][mini_quantity]"
                                    value="{{$item['mini_quantity']}}" class="layui-input" min='1'>
                            </td>
                            <td>
                                <input type="number" name="goods[{{$kk}}][buy_num]" value="{{$item['buy_num']}}"
                                    class="layui-input" min='1'>
                            </td>
                            <td>
                                <input type="number" name="goods[{{$kk}}][get_num]" value="{{$item['get_num']}}"
                                    class="layui-input" min='0'>
                                <input type="hidden" name="goods[{{$kk}}][goods_id]" value="{{$item['id']}}">
                            </td>
                        </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label"></label>
                <input type="hidden" value="{{ $data['id'] }}" name="id">
                <button class="layui-btn" lay-filter="add" lay-submit="">提交</button>
            </div>
        </form>
    </div>
</div>
<script>
layui.use(['form', 'layer', 'jquery'], function() {
    $ = layui.jquery;
    var form = layui.form,
        layer = layui.layer;

    //监听提交
    form.on('submit(add)', function(data) {
        console.log(data);
        //发异步，把数据提交给php
        $.ajax({
            type: 'POST',
            url: '/admin/store/storeGoodsAdd',
            data: data.field,
            dataType: 'json',
            headers: {
                'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
            },
            success: function(data) {
                layer.alert(data.msg)
                if (data.code == 1) {
                    //关闭当前frame
                    xadmin.close();
                    // 可以对父窗口进行刷新
                    xadmin.father_reload();
                }
            },
            error: function(xhr, type) {
                alert('Ajax error!')
            }
        });
        return false;
    });

});
</script>
@endsection